classdef Generator < Instrument
    %GENERATOR Summary of this class goes here
    %   Detailed explanation goes here
        
    properties
        frequency
        power
        output_state
        reference
    end
    
    methods(Static)
        function test()
            RF = Generator(0, 27);
            LO = Generator(0, 28);
            try
                RF.set_frequency(1.3);
                RF.set_power(0.4);
                RF.set_output_state('on');
                pause(5);

                LO.set_frequency(1.354);
                LO.set_power(-0.4);
                LO.set_output_state('on');
                pause(5);
                RF.set_output_state('off');
                LO.set_output_state('off');
            catch error
                disp(error)
            end
            RF.delete();
            LO.delete();
        end
    end
    
    methods
        function this = Generator(GPIB_controller, GPIB_address, address)
            this = this@Instrument(GPIB_controller, GPIB_address, address);
        end
        
        function delete(this)            
            this.set_output_state('off');
            this.set_power(-30);
            delete@Instrument(this);
            disp('delete generator');
        end
        
        function set_frequency(this, frequency)
            this.frequency = frequency;
            fprintf(this.conn,'FREQ %fGHz',this.frequency);
        end
        
        function set_reference(this, reference)
            this.reference = reference;
            fprintf(this.conn,'ROSC:SOUR %s', reference);
        end
        
        function set_power(this, power)
            this.power = power;
            fprintf(this.conn,'POW %fdBm',this.power);
        end
        
        function set_output_state(this, output_state)
            this.output_state = output_state;
            fprintf(this.conn, ['OUTP ' this.output_state]);
        end
    end
    
end

